/**
 * org.assess.oa.system.action.TbUserAction
 */
package org.assess.oa.system.action;

import org.apache.commons.lang.xwork.StringUtils;
import org.assess.core.action.BaseAction;
import org.assess.oa.system.bean.TbUser;
import org.assess.oa.system.service.TbUserService;

/**
 * @description 用户管理的Action
 * @author XiaLongxiang
 * @createtime 2012-5-17 下午2:18:37
 */
public class TbUserAction extends BaseAction {
    /** 序列化号 */
    private static final long serialVersionUID = -7054596427165283199L;
    
    private TbUser user;
    
    private TbUserService tbUserService;
    
    /**
     * 跳转到用户管理页面
     * @return
     */
    public String showUserJsp() {
        return SUCCESS;
    }
    
    /**
     * 分页查询用户信息
     * @return
     */
    public String listUser() {
        String jsonString = this.tbUserService.queryTbUserAsString(super.getPage(), super.getRows(), user);
        super.setJsonString(jsonString);
        return SUCCESS;
    }
    
    /**
     * 加载用户信息
     * @return
     */
    public String loadUser() {
        if (user != null && StringUtils.isNotBlank(user.getUser_code())) {
            super.setEdit(true);
            user = this.tbUserService.queryTbUserByCode(user);
        }
        
        return SUCCESS;
    }
    
    /**
     * 保存用户信息
     * @return
     */
    public String saveUser() {
        boolean result = this.tbUserService.saveUser(user, super.isEdit());
        if (result) {
            super.setMessage(super.getText("G_SAVE_001", new String[] {super.getText("ST_USER_000")}));
        }
        else {
            super.setMessage(super.getText("G_SAVE_002", new String[] {super.getText("ST_USER_000")}));
        }
        return SUCCESS;
    }
    
    /**
     * 检查用户，主要是检查用户编码是否重复
     * @return
     */
    public String checkUser() {
        String jsonString = this.tbUserService.checkUser(user);
        super.setJsonString(jsonString);
        return SUCCESS;
    }
    
    /**
     * 更改用户的valid_flag属性
     * @return
     */
    public String updateValid() {
        if (user == null) {
            user = new TbUser();
        }
        
        user.setUser_code(super.getId());
        String jsonString = this.tbUserService.updateValid(user);
        super.setJsonString(jsonString);
        return SUCCESS;
    }
    
    public TbUser getUser() {
        return user;
    }
    
    public void setUser(TbUser user) {
        this.user = user;
    }
    
    public void setTbUserService(TbUserService tbUserService) {
        this.tbUserService = tbUserService;
    }
}
